package cn.wolfcode.mapper;

import cn.wolfcode.domain.User1;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DataMapperO {
    //用户集合
    private static Map<String, User1> userData = new HashMap<String, User1>();
    //角色集合
    private static Map<String, List<String>> roleData = new HashMap<String, List<String>>();
    //权限集合
    private static Map<String, List<String>> permissionData = new HashMap<String, List<String>>();

    /*static{
        //初始化用户数据
        User u1 = new User("lanxw","666");
        userData.put(u1.getUsername(),u1);
        roleData.put(u1.getUsername(), Arrays.asList("seller"));
        permissionData.put(u1.getUsername(),
                Arrays.asList("customer:list","customer:save"));

        User u2 = new User("yl","888");
        userData.put(u2.getUsername(),u2);
        roleData.put(u2.getUsername(), Arrays.asList("seller","hr"));
        permissionData.put(u1.getUsername(),
                Arrays.asList("customer:list","customer:save","user:list","user:delete"));
    }*/

    // 加密使用
    static{
        //初始化用户数据
        //密码是666,加密3次
        User1 u1 = new User1("lanxw","0e03fc180e8385a9c72f71bf427a79e0","45cb27");
        userData.put(u1.getUsername(),u1);
        //密码是888，加密三次
        User1 u2 = new User1("yl","1d3518c269000c9c506fac6b8276dcdc","c4eb61");
        userData.put(u2.getUsername(),u2);
    }

    //提供静态方法，模拟数据库返回数据
    public static User1 getUserByName(String username){
        return userData.get(username);
    }
    public static List<String> getRoleByName(String username){
        return roleData.get(username);
    }
    public static List<String> getPermissionByName(String username){
        return permissionData.get(username);
    }

}
